package com.ruoyi.edh.mapper;

import java.util.List;
import java.util.Map;

import com.ruoyi.edh.domain.EdhReturnGoods;
import com.ruoyi.edh.domain.model.EdhReturnGoodsModel;
import com.ruoyi.edh.domain.vo.EdhDetailsReturnGoodsVo;
import com.ruoyi.edh.domain.vo.EdhReturnGoodsVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 易订购-退回退货Mapper接口
 *
 * @author xxx
 * @date 2020-09-03
 */
public interface EdhReturnGoodsMapper {
    /**
     * 查询易订购-退回退货
     *
     * @param id 易订购-退回退货ID
     * @return 易订购-退回退货
     */
    public EdhReturnGoods selectEdhReturnGoodsById(Long id);

    /**
     * 查询易订购-退回退货列表
     *
     * @param edhReturnGoods 易订购-退回退货
     * @return 易订购-退回退货集合
     */
    public List<EdhReturnGoods> selectEdhReturnGoodsList(EdhReturnGoods edhReturnGoods);

    /**
     * 查询易订购-退回退货列表
     *
     * @param edhReturnGoods 易订购-退回退货
     * @return 易订购-退回退货集合
     */
    public List<EdhReturnGoodsVo> selectEdhReturnGoodsVoList(EdhReturnGoodsModel.SearchModel edhReturnGoods);

    /**
     * 退货详情(服务单信息)
     */
    public EdhDetailsReturnGoodsVo selectEdhReturnGoodsDetailById(Long id);

    /**
     * 新增易订购-退回退货
     *
     * @param edhReturnGoods 易订购-退回退货
     * @return 结果
     */
    public int insertEdhReturnGoods(EdhReturnGoods edhReturnGoods);

    /**
     * 修改易订购-退回退货
     *
     * @param edhReturnGoods 易订购-退回退货
     * @return 结果
     */
    public int updateEdhReturnGoods(EdhReturnGoods edhReturnGoods);

    /**
     * 获取退货单各状态的数量
     */
    public Map<String, Object> getStatusNumber();

    /**
     * 删除易订购-退回退货
     *
     * @param id 易订购-退回退货ID
     * @return 结果
     */
    public int deleteEdhReturnGoodsById(Long id);

    /**
     * 批量删除易订购-退回退货
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteEdhReturnGoodsByIds(Long[] ids);


    /**
     * 根据退货订单id查询退货商品信息
     *
     * @param returnGoodsId
     * @return
     */
    @Select(" select  goods.image , goods.title name , specifications.shop_price price , specifications.specifications " +
            " , order1.goods_number `number`,specifications.store_count stock ,specifications.shop_price*order1.goods_number subtotal  " +
            " from edh_return_goods rgoods " +
            " left join edh_order order1 on rgoods.order_id = order1.id" +
            " left join edh_goods_specifications specifications on order1.goods_specifications_id = specifications.id" +
            " left join edh_goods goods on specifications.goods_id = goods.id" +
            " where rgoods.id = #{returnGoodsId}")
    public List<Map<String, Object>> selectReturnGoodsByRgid(@Param("returnGoodsId") Long returnGoodsId);

    int deleteEdhReturnGoodsByOrderId(@Param("orderId") Long orderId);

    @Select("select order_id orderId , return_reason returnResason , date_format(create_time,'%Y-%m-%d') createTime" +
            " , certificate , date_format(audit_time,'%Y-%m-%d') auditTime , date_format(cancel_time,'%Y-%m-%d') cancelTime from edh_return_goods where order_id = #{orderId} ")
    Map<String, Object> getDetail(@Param("orderId") Long orderId);
}
